# coding=utf-8
import threading
import random
import time
import sys

a = 0


def functionA():
    while True:
        num = random.randint(0, 9)
        # print num
        if num <= 1:
            global a
            a = 1
        else:
            a = 0
        time.sleep(1)


def functionB():

    while True:
        # print 'a=' + str(a)
        if a == 0:
            print "前进"
        else:
            print "转向"
        time.sleep(1)


threads = []
t1 = threading.Thread(target=functionA, args=())
threads.append(t1)
t2 = threading.Thread(target=functionB, args=())
threads.append(t2)

if __name__ == '__main__':

    for t in threads:
        # t.setDaemon(True)
        t.start()
